﻿@model Fcom.VNInsurance.Web.Models.Coverage
           
@{
    ViewBag.Title = "CoverageCProductIDMN";
    Layout = "~/Views/Shared/_CpanelLayout.cshtml";
    var cproduct =(Fcom.VNInsurance.Web.Models.CompanyProductLang)ViewBag.CProduct ;
    var company = (Fcom.VNInsurance.Web.Models.CompanyLang)ViewBag.companyLang;
    var coveragelist = (SelectList)ViewBag.coveragelist;
}
<a href="@Url.Action("ManageProductByID", new { ID=cproduct.CompanyProduct.ProductID})">Back</a>
<h3>Quản lý nhóm quyền lợi sản phẩm: @cproduct.DisplayName</h3>
Công ty: @company.CompanyName <br />

@if (Model == null)
{
    
        <form method="post">
        Tạo nhóm quyền lợi : @Html.DropDownListFor(m=>m.ID,coveragelist,null,null)
            @Html.Hidden("CProductID",cproduct.CProductID)
            <input type="submit" value="Lưu"/>
        </form>
   
}
else
{ 
  
<link rel="stylesheet" href="@Url.Content("~/Content/jqwidgets/styles/jqx.base.css")" type="text/css" />
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxcore.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxdata.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxbuttons.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxscrollbar.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxmenu.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxcheckbox.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxlistbox.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxdropdownlist.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.sort.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.pager.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.selection.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.edit.js")"></script> 
<script type="text/javascript">
        $(document).ready(function () {
           
            var url = "@Url.Action("getBenefitCP", "CompanyProduct", new { ID=cproduct.CProductID})";
            // prepare the data
            //b.RateBenefit,b.Rate
            var source =
            {
                datatype: "json",
                datafields: [
                    { name: 'BenefitID', type: 'int' },
                     { name: "MotoUpInsuranceFare", type: "string" },
                        { name: "MotoDownInsuranceFare", type: "string" },
                        {name:"MotobikeCCFare",type:"bool"},
                    { name: 'DisplayName', type: 'string' },
                    { name: 'InsuanceFare', type: 'string' },
                    { name: 'InsuanceMoney', type: 'string' },
                       { name: "RateBenefit", type: "bool" },
                    { name: 'Rate', type: 'float' }
                        , { name: 'InsmoneyByPrice', type: 'bool' }
              //InsmoneyByPrice
                ],
                id: 'BenefitID',
                url: url
            };
           

            var dataAdapter = new $.jqx.dataAdapter(source, {
                downloadComplete: function (data, status, xhr) { },
                loadComplete: function (data) { },
                loadError: function (xhr, status, error) { }
            });
            // initialize jqxGrid
            $("#jqxgrid").jqxGrid(
            {
                width: 1150,
                source: dataAdapter,
                pageable: true,
                autoheight: true,
                sortable: true,
                altrows: true,
                enabletooltips: true,
                editable: true,
                selectionmode: 'multiplecellsadvanced',
                columns: [
                  { text: 'ID', datafield: 'BenefitID', width: 30 },
            
                   { text: 'Quyền Lợi', datafield: 'DisplayName', width: 300 }, { text: 'Số tiền bảo hiểm', datafield: 'InsuanceMoney', width: 100 },
                    { text: 'STBH= giá xe', columntype: 'checkbox', datafield: 'InsmoneyByPrice', width: 100 },
               { text: 'Phí bảo hiểm', datafield: 'InsuanceFare', width: 100 },
                  
              
                  { text: 'Phí XiLanh', columntype: 'checkbox', datafield: 'MotobikeCCFare', width: 100 },
                    { text: '>50cm3', datafield: 'MotoUpInsuranceFare', width: 100 },
                                { text: '<50cm3', datafield: 'MotoDownInsuranceFare', width: 100 },
                                 { text: 'Phí tỉ lệ', columntype: 'checkbox', datafield: 'RateBenefit', width: 80 },

                                    { text: 'Tỉ lệ', datafield: 'Rate', width: 50 },
                        
                  {
                     text: 'Chỉnh sửa phí và số tiền bảo hiểm', datafield: 'Edit', columntype: 'button', width: 230, cellsrenderer: function () {
                         return "Edit";
                     }, buttonclick: function (editrow) {

                         var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
                         window.location = "@Url.Action("EditBenefitFare", "CompanyProduct")/@(company.CompanyID)/"+dataRecord.BenefitID+"/@(cproduct.CProductID)";
                     }
                  },
                  {
                      text: 'Xóa', datafield: 'Xóa', columntype: 'button', width: 100, cellsrenderer: function () {
                          return "Xóa";
                      }, buttonclick: function (editrow) {

                          var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
                          var rr = confirm("Bạn có muốn xóa bài viết \"" + dataRecord.DisplayName + "\" ?");
                          if (rr) {
                              //(int BenefitID,int CompanyProductID)

                              $.ajax({
                                  type: "post",
                                  url: "@Url.Action("benefitCPremove","CompanyProduct")",
                                  data: { BenefitID: dataRecord.BenefitID,CompanyProductID:'@cproduct.CProductID'},
                                  datatype: "json",
                                  success: function (rvdata) {
                                      if (rvdata) {
                                          $("#jqxgrid").jqxGrid({ source: dataAdapter });
                                      }
                                  }

                              });
                          }//end rr

                      }
                  }
                ]                
            });
        });
    </script>
<div class="container" style="padding:10px;">

    <h3>@Model.Name</h3>
 @Html.ActionLink("Thêm quyền lợi", "AddCPBenefit", "CompanyProduct", new { ID=cproduct.CProductID}, null)
    <br /><br />
   <div id="jqxgrid" class="container">

   </div>
</div>

      
}









